package yd.launcher;

import com.formdev.flatlaf.FlatIntelliJLaf;
import yd.launcher.service.DataService;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class R {
    /*public static final class drawable{
        public static Image logoImage;
    }
    public static final class string{
        public static String DjxtPath;
    }*/
    //配置存储文件
    public static final Path CONFIG_FILE_PATH = Paths.get(System.getProperty("user.home"),".YangApps","MyLauncher","mylauncher.config");
    //图标
    public static Image iconImage;
    //管理所有text的undo和redo
    public static TextUndoManager textUndoManager;
    //panels配置
    public static DataService dataService;

    //View
    public static JFrame frame;

    static {
        try {
            iconImage= ImageIO.read(R.class.getResourceAsStream("/images/rocket.ico"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        textUndoManager = new TextUndoManager();
        dataService = new DataService(CONFIG_FILE_PATH);
    }

    public static void main(String[] args) throws IOException {
        if (System.getProperty("java.home") == null){
            System.setProperty("java.home", ".");
        }
        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread t, Throwable e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(frame, e.getMessage());
            }
        });
        FlatIntelliJLaf.setup();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                frame = new MainFrame();
            }
        });
    }
}
